package com.yc.txx.servlet;

import com.google.gson.Gson;
import com.yc.txx.biz.BizExcpetion;
import com.yc.txx.biz.LeaseBiz;
import com.yc.txx.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/BackServlet.s")
public class BackServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String id = request.getParameter("id");
        final String cid = request.getParameter("cid");
        Result result;
        try {
            new LeaseBiz().back(id,cid);
            result = Result.success("还车成功!");
        } catch (BizExcpetion bizExcpetion) {
            bizExcpetion.printStackTrace();
            result = Result.failure(bizExcpetion.getMessage());
        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

}
